package com.gantzgulch.pairing.widgetcomparator;

import java.math.BigDecimal;

public class Widget implements Cloneable {

	private Long       id;
	private BigDecimal price;
	private String     description;
	private String     manufacturer;

	/**
	 * Widget IDs are not mutable.
	 * 
	 * @param id
	 */
	public Widget(Long id){
		if( id == null ){
			throw new IllegalArgumentException("ID must not be null.");
		}
		this.id = id;
	}
	
	public Widget(Long id, BigDecimal price, String description, String manufactuer){
		this(id);
		this.price = price;
		this.description = description;
		this.manufacturer = manufactuer;
	}

	public Long getId(){
		return id;
	}
	
	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getManufacturer() {
		return manufacturer;
	}

	public void setManufacturer(String manufacturer) {
		this.manufacturer = manufacturer;
	}

	@Override
	public boolean equals(Object obj) {
		if( obj instanceof Widget ){
			Widget widget = (Widget)obj;
			return id.equals(widget.getId());
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		return id.intValue();
	}
	
	@Override
	public Widget clone() throws CloneNotSupportedException {
		return (Widget)super.clone();
	}
}
